package org.fireflow2.designer.eclipse.commands.connection;

import org.eclipse.gef.commands.Command;
import org.fireflow2.designer.eclipse.modelwrapper.NodeWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.SubProcessWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.basic.GroupWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.basic.TransitionWrapper;

public class DeleteTransitionCommand extends Command {
	TransitionWrapper transitionWrapper = null;
	NodeWrapper source = null;
	NodeWrapper target = null;
	
	SubProcessWrapper subProcessWrapper = null;

	public TransitionWrapper getTransitionWrapper() {
		return transitionWrapper;
	}

	public void setTransitionWrapper(TransitionWrapper transitionWrapper) {
		this.transitionWrapper = transitionWrapper;
		source = (NodeWrapper)transitionWrapper.getSource();
		target = (NodeWrapper)transitionWrapper.getTarget();
		subProcessWrapper = (SubProcessWrapper)transitionWrapper.getParent();
	}
	
	public void setSubProcessWrapper(SubProcessWrapper subProcessWp){
		this.subProcessWrapper = subProcessWp;
	}
	

//	public NodeWrapper getSource() {
//		return source;
//	}
//
//	public void setSource(NodeWrapper source) {
//		this.source = source;
//	}
//
//	public NodeWrapper getTarget() {
//		return target;
//	}
//
//	public void setTarget(NodeWrapper target) {
//		this.target = target;
//	}

	public void execute() {
		try {
			source.removeLeavingTransition(transitionWrapper);
			target.removeEnteringTransition(transitionWrapper);
			subProcessWrapper.deleteChild(transitionWrapper);
			transitionWrapper.setSource(null);
			transitionWrapper.setTarget(null);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public String getLabel() {
		return "Delete Transition";
	}

	public void redo() {
		execute();
	}

	public void undo() {
		transitionWrapper.setSource(source);
		transitionWrapper.setTarget(target);
		source.addLeavingTransition(transitionWrapper);
		target.addEnteringTransition(transitionWrapper);
		subProcessWrapper.addChild(transitionWrapper);
	}
}
